home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / dbasedt3.zip / DBASEDIT.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  39KB  |  1,677 lines

  1.     PAGE    80,132
  2.     TITLE    DBASEDIT Editor for text entry in dBASE III
  3.  
  4. ;    .BIN program to use a window inside the dBASE program to create or
  5. ;       modify a text file.  Used by LOADing the program under dBASE then
  6. ;    CALLing it with a parameter list.  The parameter list is generated
  7. ;    in dBASE as a concatenated text string.  There are 5 3 byte ASCII
  8. ;    strings with the folowing parameters, in order:
  9. ;        first row of the edit window
  10. ;        last row of the edit window
  11. ;        first column of the edit window
  12. ;        last column of the edit window
  13. ;        max number of lines for the data
  14. ;    They are followed by the 12 byte file name (includes extension) and
  15. ;    one character which should be a Y or N and indicates to DBASEDIT
  16. ;    whether data will be input (Y) or just displayed in the window (N).
  17. ;
  18. ;    Assemble the source (this version used the Microsoft Macro Assembler
  19. ;    Version 5.0), then LINK and EXE2BIN.
  20. ;
  21. ;    Following is a sample segment of dBASE source code to use DBASEDIT:
  22. ;
  23. COMMENT ^ ...Set up code goes here
  24. LOAD DBASEDIT
  25. ...
  26. FIRSTROW = 2
  27. FIRSTCOL = 1
  28. LASTROW = 23
  29. LASTCOL = 78
  30. MAXLINES = 44
  31. FILENAM = 'HELPXXXX.TXT'
  32. DOANS = 'Y'
  33. PARM = STR(FIRSTROW,3) + STR(LASTROW,3) + STR(FIRSTCOL,3) + ;
  34. STR(LASTCOL,3) + STR(MAXLINES,3) + FILENAM + DOANS
  35. @ FIRSTROW-1,FIRSTCOL-1 TO LASTROW+1,LASTCOL+1 DOUBLE
  36. IF ISCOLOR()
  37.    SET COLOR TO W+/R
  38. ENDIF
  39. @ FIRSTROW,FIRSTCOL CLEAR TO LASTROW,LASTCOL
  40. @ LASTROW+1,18 SAY '[ Press F1 for Editor Help/ F10 when done. ]'
  41.  
  42. CALL DBASEDIT WITH PARM
  43.  
  44. RELEASE DBASEDIT
  45. .... other processing follows ^
  46. ;
  47. ;    The above code would look for the file HELPTEMP.TXT and move the
  48. ;    data from it to the screen if it is found.  At the end of editting,
  49. ;    a file by that name would be created.  I created the file from a
  50. ;    dBASE data base then restore the original data base by appending
  51. ;    from the created file.  It works well and allows some word processor
  52. ;    type editting on a dBASE screen.  Look at the code or use the routine
  53. ;    and press F1 to find out which keys are used and what their functions
  54. ;    are.
  55.  
  56. ;    Macros
  57.  
  58. .SALL
  59.  
  60. PUSHALL    MACRO
  61.     PUSHF
  62.     PUSH    AX
  63.     PUSH    BX
  64.     PUSH    CX
  65.     PUSH    DX
  66.     PUSH    SI
  67.     PUSH    DI
  68.     PUSH    BP
  69.     PUSH    DS
  70.     PUSH    ES
  71.     PUSH    SS
  72.     ENDM
  73.  
  74. POPALL    MACRO
  75.     POP    SS
  76.     POP    ES
  77.     POP    DS
  78.     POP    BP
  79.     POP    DI
  80.     POP    SI
  81.     POP    DX
  82.     POP    CX
  83.     POP    BX
  84.     POP    AX
  85.     POPF
  86.     ENDM
  87.  
  88. GCRSR    MACRO
  89. ;;        Gets the current cursor column,row position in DL,DH.
  90.     PUSH    AX
  91.     PUSH    BX
  92.     PUSH    CX
  93.     XOR    BX,BX            ;;set for page 0
  94.     MOV    AH,03H            ;;function code
  95.     INT    010H
  96.     POP    CX
  97.     POP    BX
  98.     POP    AX
  99.     ENDM
  100.  
  101. SCRSR    MACRO
  102. ;;        Sets cursor to column,row position in DL,DH
  103.     PUSH    AX
  104.     PUSH    BX
  105.     XOR    BX,BX
  106.     MOV    AH,02H
  107.     INT    010H
  108.     POP    BX
  109.     POP    AX
  110.     ENDM
  111.  
  112. WCRSR    MACRO
  113. ;;        Writes the character in AL at the current cursor location
  114.     PUSH    AX
  115.     PUSH    BX
  116.     PUSH    CX
  117.     XOR    BX,BX
  118.     MOV    CX,1
  119.     MOV    AH,0AH
  120.     INT    010H
  121.     POP    CX
  122.     POP    BX
  123.     POP    AX
  124.     ENDM
  125.  
  126. WCRSR2    MACRO
  127. ;;        Writes the character in AL at the current cursor location
  128.     PUSH    AX
  129.     PUSH    BX
  130.     XOR    BX,BX
  131.     MOV    AH,0EH
  132.     INT    010H
  133.     POP    BX
  134.     POP    AX
  135.     ENDM
  136.  
  137. CSEG    SEGMENT    BYTE
  138.     ASSUME CS:CSEG,DS:CSEG,ES:CSEG
  139.  
  140.     ORG    0H
  141.  
  142.     PUBLIC    DBASEDIT
  143.  
  144. DBASEDIT    PROC    FAR
  145.     JMP    EDITEXT
  146.  
  147. NUL    EQU    0
  148. BEL    EQU    07H
  149. CR    EQU    0DH
  150. LF    EQU    0AH
  151. EOF    EQU    01AH
  152. EOL    EQU    '$'
  153. LINELEN    EQU    75            ;default line length
  154. MAXLEN    EQU    LINELEN * 100        ;default max buffer size
  155.  
  156. THREE_BLANKS    DB    '   '
  157. INS_STRING    DB    'Ins'
  158. FILENAME    DB    'DBASEDIT.TXT',NUL
  159. ERR1        DB    CR,LF,'Requested space exceeds maximum allowed. Will use max of 7500 bytes.',EOL
  160. ERR2        DB    CR,LF,"Can't create work file. Check disk space available. Must exit.",EOL
  161. ;    HELP text and JMP tables listings suppressed
  162. .XLIST
  163. HELP_TEXT    DB    '                            AADS Editor Help Screen',CR,LF
  164. L2        DB    '  Key                  Function',CR,LF
  165. L3        DB    ' F1          Invokes this Help screen.',CR,LF
  166. L4        DB    ' F3          Inserts a line at the cursor position.',CR,LF
  167. L5        DB    ' F5          Deletes the line at the cursor position.',CR,LF
  168. L6        DB    ' F7          Deletes from the cursor to end of text.',CR,LF
  169. L7        DB    ' F10         Ends the Editor session and resumes AADS processing.',CR,LF
  170. L8        DB    ' Tab         Moves cursor to next tab position. (Tabs are set 8 spaces apart.)',CR,LF
  171. L9        DB    ' Home        Moves cursor to beginning of current line.',CR,LF
  172. L10        DB    ' End         Moves cursor to end of current line.',CR,LF
  173. L11        DB    ' Ctrl/End    Clears text to end of line.',CR,LF
  174. L12        DB    ' PgUp        Scrolls the window to the previous page.  Shows first line of ',CR,LF
  175. L13        DB    '              text if scroll is at or past top.',CR,LF
  176. L14        DB    ' Ctrl/PgUp   Moves to beginning of first window of text.',CR,LF
  177. L15        DB    ' PgDn        Scrolls the window to the next full page.  Stops at last line of',CR,LF
  178. L16        DB    '              text if scroll is at or past bottom.',CR,LF
  179. L17        DB    ' Ctrl/PgDn   Moves to beginning of last window of text.',CR,LF
  180. L18        DB    ' Backspace   Deletes the charcter ahead of the cursor and moves all following',CR,LF
  181. L19        DB    '              characters forward one space.',CR,LF
  182. L20        DB    ' Del         Same as Backspace but deletes character under cursor.',CR,LF
  183. L21        DB    ' Ins         Puts Editor in Insert mode.  Operates just like dBASE.',CR,LF
  184. L22        DB    ' Cursor Keys Move the cursor through the text without changing it.',CR,LF
  185. L23        DB    CR,LF
  186. L24        DB    '* NOTE - Undefined keys or keys at their limits will beep.',CR,LF,EOL
  187. L25        DB    CR,LF
  188. .LIST
  189.  
  190. IN_FIELD    DB    '011021003077020EDITXT.TXT  Y'    ;defaults
  191.         DB    NUL,EOL
  192. ARGUMENT    DB    3 DUP(0)
  193.         DB    0
  194. CR_LF        DB    CR,LF
  195. END_OF_FILE    DB    EOF
  196. HOLD_CHAR    DB    0
  197. HCURSOR_SAVE    DB    0
  198. INSERT_TOGGLE    DB    0
  199. FIRST_ROW    DB    13
  200. LAST_ROW    DB    22
  201. FIRST_COLUMN    DB    3
  202.         DB    0
  203.         ORG    $-2
  204. FIRST_COL_WORD    DW    ?
  205. EXEC_FLAG    DB    ' '
  206. LAST_COLUMN    DB    77
  207. ATTRIBUTE    DB    0
  208. INSERT_STATUS    DB    0
  209. LINE_BUFFER    DB    80 DUP(0)    ;for existing file input
  210. HELP_SW        DB    0
  211. IN_LAST_PAGE    DB    0
  212.  
  213. SKIP_FLAG    DW    0        ;cancels scroll in ADVANCE_CURSOR
  214. IN_LINE_COUNT    DW    0
  215. FIELD_LENGTH    DW    MAXLEN        ;start at max
  216. HANDLE        DW    0
  217. PGWIDTH        DW    0
  218. WINDOW_LINES    DW    0        ;number of lines in window
  219. SCROLL_PAGE    DW    0        ;page we're now in
  220. PAGE_SIZE    DW    0        ;number of characters in a page
  221. BUFFER_END    DW    0        ;address of end of buffer
  222.  
  223. BUFFER_LEFT    DW    0        ;holds number of remaining chars
  224. BUFFER_POSITION    DW    0        ;holds character position
  225. LINE_POSITION    DW    1        ;holds number of chars on line so far
  226. INPUT_SIZE    DW    0        ;holds size of input text
  227. OUTPUT_LINES    DW    0
  228. REG4        DW    0
  229. REG5        DW    0
  230. REG8        DW    0
  231. ;
  232. ;    Keyboard Function Codes Tables
  233.  
  234. FUNCTAB        STRUC
  235. FUNCCODE    DB    00H
  236. FUNCADDR    DW    0000H
  237. FUNCTAB        ENDS
  238.  
  239. .XLIST
  240. ;    Function Codes
  241.  
  242. ;    Regular keyboard characters
  243.  
  244. XTNCHR    EQU    00
  245. XITCHR    EQU    03            ;exit to system (^C or CtrlBrk)
  246. BAKCHR    EQU    08            ;destructive back space
  247. TABCHR    EQU    09            ;forward tab
  248. LFDCHR    EQU    10            ;line feed/new line
  249. RETCHR    EQU    13            ;carriage return
  250. EOFCHR    EQU    26            ;end of file character
  251. ESCCHR    EQU    27            ;ESC character
  252.  
  253. ;    Extended Function Codes
  254.  
  255. F1CHR    EQU    59            ;F1 key
  256. F2CHR    EQU    60            ;F2 key
  257. F3CHR    EQU    61
  258. F4CHR    EQU    62
  259. F5CHR    EQU    63
  260. F6CHR    EQU    64
  261. F7CHR    EQU    65
  262. F8CHR    EQU    66
  263. F9CHR    EQU    67
  264. F10CHR    EQU    68
  265. HMECHR    EQU    71
  266. UPCCHR    EQU    72            ;up cursor
  267. PAGEUP    EQU    73            ;page up
  268. LFTCUR    EQU    75            ;cursor left
  269. RHTCUR    EQU    77            ;cursor right
  270. ENDCHR    EQU    79            ;END
  271. DWNCHR    EQU    80            ;down cursor
  272. PAGEDN    EQU    81            ;page down
  273. INSCHR    EQU    82            ;INS
  274. DELCHR    EQU    83            ;DEL
  275. CLREOL    EQU    117            ;Ctrl/End
  276. ENDSCN    EQU    118            ;Ctrl/PgDn
  277. TOP    EQU    132            ;Ctrl/PgUp
  278.  
  279. ;    Function Table
  280.  
  281. REG_KEYS:
  282.     FUNCTAB    <RETCHR,DO_RETURN>
  283.     FUNCTAB    <XTNCHR,XTN_CHK>    ;extended ASCII coming
  284.     FUNCTAB    <TABCHR,DO_TAB>
  285.     FUNCTAB    <BAKCHR,BACK_SPACE>
  286.     FUNCTAB    <EOFCHR,DO_END>        ;same as END
  287.     FUNCTAB    <XITCHR,DO_BREAK>    ;control break
  288.     FUNCTAB    <LFDCHR,DO_RETURN>
  289.     FUNCTAB    <ESCCHR,DO_ESCAPE>
  290.  
  291. REG_KEYS_ENTS    EQU    ($-REG_KEYS)/TYPE FUNCTAB
  292.  
  293. EXTN_KEYS:
  294.     FUNCTAB    <F1CHR,HELP>
  295.     FUNCTAB    <F2CHR,BAD_KEY>
  296.     FUNCTAB    <F3CHR,INSERT_LINE>
  297.     FUNCTAB    <F4CHR,BAD_KEY>
  298.     FUNCTAB    <F5CHR,DELETE_LINE>
  299.     FUNCTAB    <F6CHR,BAD_KEY>
  300.     FUNCTAB    <F7CHR,DELETE_TO_EOT>
  301.     FUNCTAB    <F8CHR,BAD_KEY>
  302.     FUNCTAB    <F9CHR,BAD_KEY>
  303.     FUNCTAB    <F10CHR,GET_LINE_END>
  304.     FUNCTAB    <INSCHR,INSERT>
  305.     FUNCTAB    <DELCHR,DELETE_CHAR>
  306.     FUNCTAB    <ENDCHR,DO_END>
  307.     FUNCTAB    <LFTCUR,CURSOR_LEFT>
  308.     FUNCTAB    <RHTCUR,CURSOR_RT>
  309.     FUNCTAB    <HMECHR,HOME_KEY>
  310.     FUNCTAB    <UPCCHR,CURSOR_UP>
  311.     FUNCTAB    <PAGEUP,DO_PAGE_UP>
  312.     FUNCTAB    <DWNCHR,CURSOR_DOWN>
  313.     FUNCTAB    <PAGEDN,DO_PAGE_DOWN>
  314.     FUNCTAB    <XITCHR,DO_BREAK>
  315.     FUNCTAB    <CLREOL,CLEAR_TO_EOL>
  316.     FUNCTAB    <TOP,START_SCREEN>
  317.     FUNCTAB    <ENDSCN,END_SCREEN>
  318.  
  319. EXTN_KEYS_ENTS    EQU    ($-EXTN_KEYS)/TYPE FUNCTAB
  320.  
  321. ;    End of tables
  322.  
  323. .LIST
  324.  
  325.     SUBTTL    Program Code
  326.     PAGE
  327. EDITEXT        PROC    NEAR
  328.     PUSHALL
  329.      MOV    AX,CS
  330.     MOV    ES,AX
  331.     MOV    DI,Offset IN_FIELD
  332.     MOV    SI,BX
  333.     MOV    CX,28
  334.     REP    MOVSB
  335.     PUSH    ES
  336.     POP    DS
  337.     MOV    BX,Offset SCRN_BUFR_END    ;calculate program size
  338.     SUB    BX,Offset DBASEDIT
  339.     MOV    CL,4
  340.     SHR    BX,CL            ;make into paragraphs
  341.     ADD    BX,100H            ;handle excess
  342.     MOV    AH,04AH            ;modify memory function
  343.     INT    021H            ;shrink memory to program size
  344.     CLD                ;scan is up
  345.     MOV    AH,02H            ;check INS key status
  346.     INT    016H
  347.     MOV    INSERT_STATUS,AL    ;save it
  348.     TEST    AL,10000000B        ;bit 7 on?
  349.     JZ    INSERT_OFF
  350.     MOV    INSERT_TOGGLE,0FFH    ;set toggle
  351.     JMP    Short EDIT_TXT_0
  352.  
  353. INSERT_OFF:
  354.     MOV    INSERT_TOGGLE,0        ;turn toggle off
  355. EDIT_TXT_0:
  356.     CALL    SHOW_INSERT        ;put Ins on screen
  357.     MOV    HELP_SW,0        ;HELP has not been called
  358.     MOV    CX,3            ;convert input parameters
  359.     MOV    SI,Offset IN_FIELD
  360.     MOV    DI,Offset ARGUMENT
  361.     REP    MOVSB
  362.     CALL    CNVT_DEC        ;this converts input to hex in CX
  363.     MOV    FIRST_ROW,CL
  364.     MOV    CX,3            ;convert input parameters
  365.     MOV    SI,Offset IN_FIELD+3
  366.     MOV    DI,Offset ARGUMENT
  367.     REP    MOVSB
  368.     CALL    CNVT_DEC        ;this converts input to hex in CX
  369.     MOV    LAST_ROW,CL
  370.     MOV    CX,3            ;convert input parameters
  371.     MOV    SI,Offset IN_FIELD+6
  372.     MOV    DI,Offset ARGUMENT
  373.     REP    MOVSB
  374.     CALL    CNVT_DEC        ;this converts input to hex in CX
  375.     MOV    FIRST_COLUMN,CL
  376.     MOV    CX,3            ;convert input parameters
  377.     MOV    SI,Offset IN_FIELD+9
  378.     MOV    DI,Offset ARGUMENT
  379.     REP    MOVSB
  380.     CALL    CNVT_DEC        ;this converts input to hex in CX
  381.     MOV    LAST_COLUMN,CL
  382.     MOV    CX,3            ;convert input parameters
  383.     MOV    SI,Offset IN_FIELD+12
  384.     MOV    DI,Offset ARGUMENT
  385.     REP    MOVSB
  386.     CALL    CNVT_DEC        ;this converts input to hex in CX
  387.     MOV    IN_LINE_COUNT,CX    ;save for loop counts
  388.     MOV    CX,12            ;get file name input parameter
  389.     MOV    SI,Offset IN_FIELD+15
  390.     MOV    DI,Offset FILENAME
  391.     REP    MOVSB
  392.     MOV    CX,12
  393. INP_LINE_1:
  394.     DEC    DI
  395.     CMP    Byte Ptr 0[DI],' '
  396.     JNE    INP_LINE_2
  397.     MOV    Byte Ptr 0[DI],0    ;make ASCIIZ
  398.     LOOP    INP_LINE_1
  399. INP_LINE_2:
  400.     MOV    CX,1            ;get last input parameter
  401.     MOV    SI,Offset IN_FIELD+27
  402.     MOV    DI,Offset EXEC_FLAG
  403.     REP    MOVSB
  404.     XOR    AX,AX
  405.     MOV    AL,LAST_COLUMN
  406.     SUB    AL,FIRST_COLUMN
  407.     INC    AX            ;now has width of line
  408.     MOV    PGWIDTH,AX
  409.     XOR    AX,AX            ;calculate number of lines in window
  410.     MOV    AL,LAST_ROW
  411.     SUB    AL,FIRST_ROW
  412.     INC    AX
  413.     MOV    WINDOW_LINES,AX
  414.     MOV    BX,PGWIDTH
  415.     MUL    BX
  416.     MOV    PAGE_SIZE,AX
  417.     MOV    AX,Offset SCRN_BUFR
  418.     MOV    BUFFER_POSITION,AX    ;set screen position
  419.     MOV    AX,PGWIDTH
  420.     MOV    BX,IN_LINE_COUNT
  421.     MUL    BX
  422.     MOV    BUFFER_LEFT,AX        ;initialize # of remaining characters
  423.     MOV    FIELD_LENGTH,AX        ;and save it
  424.     ADD    AX,BUFFER_POSITION    ;find end of buffer + 1
  425.     MOV    BUFFER_END,AX
  426.     CMP    AX,Offset SCRN_BUFR_END
  427.     JLE    EDITXT_1
  428.     MOV    DX,Offset ERR1
  429.     MOV    AH,09H
  430.     INT    021H
  431.     CALL    BEEP
  432.     MOV    AH,08H
  433.     INT    021H
  434.     MOV    AX,MAXLEN
  435.     MOV    BUFFER_LEFT,AX        ;initialize # of remaining characters
  436.     MOV    FIELD_LENGTH,AX        ;and save it
  437.     ADD    AX,BUFFER_POSITION    ;find end of buffer + 1
  438.     MOV    BUFFER_END,AX
  439. EDITXT_1:
  440.     MOV    LINE_POSITION,1        ;initialize at start
  441.     MOV    DI,Offset SCRN_BUFR    ;clear the buffer
  442.     MOV    CX,BUFFER_LEFT
  443.     MOV    AL,' '
  444.     REP    STOSB
  445. ;                ;read existing data
  446.     MOV    DX,Offset FILENAME
  447.     MOV    AX,03D00H
  448.     INT    021H
  449.     JC    EDITXT_6        ;no file, nothing to load
  450.     MOV    HANDLE,AX        ;found, save it
  451.     MOV    BX,AX            ;and set for read
  452.     PUSH    ES
  453.     PUSH    DS
  454.     POP    ES
  455.     MOV    DI,Offset SCRN_BUFR
  456. EDITXT_2:
  457.     MOV    CX,PGWIDTH        ;read record + <CR><LF>
  458.     INC    CX
  459.     INC    CX
  460.     MOV    DX,Offset LINE_BUFFER
  461.     MOV    AH,03FH
  462.     INT    021H
  463.     CMP    AX,0
  464.     JE    EDITXT_5        ;all done, close
  465.     MOV    SI,Offset LINE_BUFFER
  466.     CMP    Byte Ptr 0[SI],EOF    ;end of file?
  467.     JE    EDITXT_5        ;yes, also done
  468. EDITXT_3:
  469.     LODSB                ;get the char
  470.     CMP    AL,' '            ;valid text character?
  471.     JL    EDITXT_4        ;no, bypass
  472.     STOSB                ;store the data in the screen buffer
  473. EDITXT_4:
  474.     LOOP    EDITXT_3        ;keep storing
  475.     JMP    EDITXT_2
  476.  
  477. EDITXT_5:
  478.     MOV    AH,03EH            ;close the file
  479.     INT    021H
  480.     POP    ES            ;restore
  481. EDITXT_6:
  482.     MOV    DH,FIRST_ROW        ;put cursor on window
  483.     MOV    DL,FIRST_COLUMN
  484.     SCRSR
  485.     MOV    AH,08H            ;now find the attribute
  486.     INT    010H
  487.     MOV    ATTRIBUTE,AH        ;save it
  488.     XOR    BX,BX            ;clear
  489.     MOV    BH,AH            ;attribute to fill with
  490.     MOV    AH,06H
  491.     MOV    AL,00H            ;initialize window
  492.     MOV    CH,FIRST_ROW
  493.     MOV    CL,FIRST_COLUMN
  494.     MOV    DH,LAST_ROW
  495.     MOV    DL,LAST_COLUMN
  496.     INT    010H
  497.     MOV    DX,CX            ;put cursor at start
  498.     SCRSR
  499.     CALL    MOVE_SCREEN        ;fill window with data if any
  500.     CMP    EXEC_FLAG,'Y'        ;execute now?
  501.     JNE    DBASEDIT_END        ;no, go return
  502. EDITXT_7:
  503.     CALL    GET_LINE        ;get a line of input
  504.     JMP    EDITXT_7
  505.  
  506. EDITEXT        ENDP
  507.  
  508. DBASEDIT_END    PROC    FAR
  509. ; Close out routine to return to dBASE program
  510.     MOV    AL,INSERT_STATUS
  511.     TEST    AL,10000000B        ;was Ins on?
  512.     JZ    EDIT_TXT_END_1        ;no
  513.     MOV    INSERT_TOGGLE,0FFH
  514.     JMP    Short EDIT_TXT_END_2
  515.  
  516. EDIT_TXT_END_1:
  517.     MOV    INSERT_TOGGLE,0
  518. EDIT_TXT_END_2:
  519.     CALL    SHOW_INSERT
  520.     PUSH    ES
  521.     MOV    AX,040H
  522.     MOV    ES,AX            ;point at BIOS data
  523.     MOV    AL,INSERT_STATUS
  524.     MOV    ES:[017H],AL
  525.     POP    ES
  526.     POPALL
  527.         RET                ;back to dBASE III
  528.  
  529. DBASEDIT_END    ENDP
  530.  
  531. GET_LINE    PROC    NEAR
  532. ;
  533.     MOV    AX,IN_LINE_COUNT    ;number of lines
  534.     MOV    BX,PGWIDTH
  535.     MUL    BX
  536.     MOV    INPUT_SIZE,AX            ;number of chars to input
  537.     MOV    CX,AX
  538. GET_LINE_LOOP1:
  539.     PUSH    CX
  540.     MOV    AH,07H            ;get char function
  541.     INT    021H
  542.     MOV    BX,Offset REG_KEYS
  543.     MOV    CX,REG_KEYS_ENTS    ;number of entries
  544. REG_LOOP:
  545.     CMP    AL,[BX].FUNCCODE    ;is this the character?
  546.     JE    FOUND_REG        ;yes
  547.     ADD    BX,TYPE FUNCTAB        ;bump pointer
  548.     LOOP    REG_LOOP
  549.     JMP    Short REG_CHAR
  550.  
  551. FOUND_REG:
  552.     MOV    AX,DS
  553.     PUSH    CS
  554.     POP    SI
  555.     SUB    AX,SI
  556.     MOV    CX,4
  557.     SHL    AX,CL
  558.     MOV    BX,[BX].FUNCADDR
  559.     ADD    BX,AX
  560.     JMP    BX            ;process the function
  561.     POP    CX
  562.     JMP    GET_LINE_LOOP1
  563.  
  564. XTN_CHK:            ;check extended character
  565.     MOV    DL,0FFH
  566.     MOV    AH,06H            ;direct I/O
  567.     INT    021H
  568.     JNZ    XTN_GOT_KEY        ;got a key
  569.     JMP    BAD_KEY
  570.  
  571. XTN_GOT_KEY:
  572.     MOV    HOLD_CHAR,AL
  573.     MOV    BX,Offset EXTN_KEYS
  574.     MOV    CX,EXTN_KEYS_ENTS
  575. XTN_LOOP:
  576.     CMP    AL,[BX].FUNCCODE
  577.     JE    FOUND_XTN
  578.     ADD    BX,TYPE FUNCTAB
  579.     LOOP    XTN_LOOP
  580.     JMP    BAD_KEY
  581.  
  582. FOUND_XTN:
  583.     MOV    AX,DS
  584.     PUSH    CS
  585.     POP    SI
  586.     SUB    AX,SI
  587.     MOV    CX,4
  588.     SHL    AX,CL
  589.     MOV    BX,[BX].FUNCADDR
  590.     ADD    BX,AX
  591.     JMP    BX            ;process the function
  592.     POP    CX
  593.     JMP    GET_LINE_LOOP1
  594.  
  595. REG_CHAR:
  596.     CMP    BUFFER_LEFT,0        ;is there room?
  597.     JNE    REG_CHAR1
  598.     JMP    BAD_KEY
  599.  
  600. REG_CHAR1:
  601.     CMP    INSERT_TOGGLE,0FFH    ;insert on?
  602.     JNE    REG_CHAR1_0
  603.     MOV    SI,BUFFER_END        ;insert mode processing
  604.     DEC    SI            ;point at last character
  605.     MOV    DI,SI            ;and next to last
  606.     DEC    SI
  607.     MOV    CX,BUFFER_LEFT        ;number to move
  608.     STD
  609.     REP    MOVSB
  610.     CLD
  611.     MOV    Byte Ptr 1[DI],' '    ;blank out current character
  612.     PUSH    AX
  613.     CALL    MOVE_SCREEN
  614.     POP    AX
  615. REG_CHAR1_0:
  616.     MOV    BX,BUFFER_POSITION    ;get buffer address
  617.     MOV    Byte Ptr 0[BX],AL    ;put character there
  618.     WCRSR                ;display the character
  619.     DEC    BUFFER_LEFT        ;decrement remaining char count
  620.     JZ    REG_CHAR_END        ;no more space, done
  621.     INC    LINE_POSITION        ;bump char count
  622.     INC    BUFFER_POSITION        ;bump buffer address
  623.     MOV    AX,BUFFER_POSITION
  624.     CMP    AX,BUFFER_END        ;at end?
  625.     JGE    REG_CHAR_END        ;yes
  626.     MOV    BX,PGWIDTH
  627.     CMP    BX,LINE_POSITION    ;at end?
  628.     JGE    REG_CHAR_0_A        ;no
  629.     MOV    LINE_POSITION,1
  630. REG_CHAR_0_A:
  631.     CALL    ADVANCE_CURSOR        ;move cursor right
  632.     JNC    REG_CHAR_1
  633.     MOV    LINE_POSITION,1
  634.     CALL    SCROLL_DOWN
  635.     MOV    BX,BUFFER_END
  636.     CMP    BX,PAGE_SIZE
  637.     JG    REG_CHAR_1
  638.     MOV    IN_LAST_PAGE,0FFH    ;set last page switch on
  639. REG_CHAR_1:
  640.     POP    CX
  641.     DEC    CX
  642.     JCXZ    REG_CHAR_END        ;can't use LOOP; too far
  643.     JMP    GET_LINE_LOOP1
  644.  
  645. REG_CHAR_END:
  646.     CALL    SET_LAST_LINE
  647.     JMP    BAD_KEY
  648.  
  649. GET_LINE    ENDP
  650.  
  651. GET_LINE_END    PROC    NEAR
  652.     POP    CX            ;clear stack
  653.     STD                ;search from end of buffer
  654.     MOV    AL,' '            ;char to look at
  655.     MOV    CX,FIELD_LENGTH        ;length to scan
  656.     MOV    DI,BUFFER_END
  657.     DEC    DI
  658.     REPZ    SCASB            ;look for first non blank
  659.     CLD                ;restore
  660.     MOV    AX,CX            ;points at last character
  661.     XOR    DX,DX
  662.     MOV    BX,PGWIDTH
  663.     DIV    BX
  664.     INC    AX
  665.     MOV    OUTPUT_LINES,AX        ;number of lines to output
  666.     MOV    AH,03CH            ;create a file
  667.     MOV    DX,Offset FILENAME
  668.     XOR    CX,CX
  669.     INT    021H
  670.     JNC    GET_LINE_END_1
  671.     PUSH    AX            ;save error code
  672.     MOV    DX,Offset ERR2
  673.     MOV    AH,09H
  674.     INT    021H
  675.     MOV    AH,08H
  676.     INT    021H
  677.     POP    AX            ;restore error
  678.     JMP    Short GET_LINE_END_RET
  679.  
  680. GET_LINE_END_1:
  681.     MOV    HANDLE,AX
  682.     MOV    BX,AX
  683.     MOV    DX,Offset SCRN_BUFR    ;set start
  684.     MOV    CX,OUTPUT_LINES        ;get count
  685. GET_LINE_END_2:
  686.     PUSH    CX
  687.     MOV    CX,PGWIDTH
  688.     MOV    AH,040H
  689.     INT    021H            ;output a record
  690.     ADD    DX,PGWIDTH        ;bump buffer pointer
  691.     PUSH    DX            ;save it
  692.     MOV    CX,2
  693.     MOV    DX,Offset CR_LF
  694.     MOV    AH,040H
  695.     INT    021H            ;write a <CR><LF>
  696.     POP    DX            ;restore buffer pointer
  697.     POP    CX            ;and count
  698.     LOOP    GET_LINE_END_2
  699.     MOV    DX,Offset END_OF_FILE
  700.     MOV    CX,1
  701.     MOV    AH,040H
  702.     INT    021H
  703.     MOV    BX,HANDLE
  704.     MOV    AH,03EH
  705.     INT    021H
  706. GET_LINE_END_RET:
  707.     POP    AX            ;clear RET
  708.     JMP    Near Ptr DBASEDIT_END
  709.  
  710. GET_LINE_END    ENDP
  711.  
  712.     SUBTTL    Key Handling Routines
  713.     PAGE
  714.  
  715. BACK_SPACE    PROC    NEAR
  716.     CALL    CUR_LFT            ;move cursor and pointers back one
  717.     JC    BACK_SPACE_ERR        ;can't do
  718.     MOV    DI,BUFFER_POSITION    ;set current location
  719.     MOV    CX,BUFFER_LEFT        ;set up move
  720.     DEC    CX
  721.     MOV    SI,DI
  722.     CMP    INSERT_TOGGLE,0FFH    ;in insert mode?
  723.     JNE    BACK_SPACE_2        ;yes, need to collapse data
  724.     INC    SI            ;collapse data by one
  725.     CLD
  726.     REP    MOVSB
  727.     MOV    Byte Ptr 0[DI],' '
  728.     JMP    BACK_SPACE_3
  729. BACK_SPACE_2:
  730.     MOV    Byte Ptr 0[DI],' '
  731. BACK_SPACE_3:
  732.     CALL    MOVE_SCREEN
  733.     JC    BACK_SPACE_ERR        ;just in case
  734.     POP    CX            ;normal return
  735.     RET
  736.  
  737. BACK_SPACE_ERR:
  738.     JMP    BAD_KEY
  739.  
  740. BACK_SPACE    ENDP
  741.  
  742. BAD_KEY    PROC    NEAR
  743.     CALL    BEEP
  744.     POP    CX
  745.     RET
  746.  
  747. BAD_KEY    ENDP
  748.  
  749. CLEAR_TO_EOL    PROC    NEAR
  750.     MOV    DI,BUFFER_POSITION    ;point at buffer position
  751.     MOV    CX,PGWIDTH
  752.     SUB    CX,LINE_POSITION    ;number of chars to clear
  753.     PUSH    CX            ;save it
  754.     GCRSR                ;save current cursor
  755.     PUSH    DX
  756.     MOV    AL,' '
  757. CLR_EOL_1:
  758.     WCRSR2
  759.     LOOP    CLR_EOL_1
  760.     POP    DX            ;restore cursor
  761.     SCRSR
  762.     POP    CX            ;get chars to clear count
  763.     MOV    AL,' '
  764.     REP    STOSB
  765.     POP    CX
  766.     RET
  767.  
  768. CLEAR_TO_EOL    ENDP
  769.  
  770. CURSOR_DOWN    PROC    NEAR
  771.     MOV    AX,BUFFER_POSITION    ;calculate buffer change
  772.     ADD    AX,PGWIDTH        ;bump one line
  773.     CMP    AX,BUFFER_END        ;will it put us past end?
  774.     JL    CURSOR_DN_1        ;no, OK to continue
  775.     JMP    BAD_KEY            ;go beep
  776.  
  777. CURSOR_DN_1:
  778.     MOV    BX,PGWIDTH
  779.     ADD    BUFFER_POSITION,BX    ;set line position count
  780.     SUB    BUFFER_LEFT,BX        ;change chars left count
  781.     GCRSR                ;get cursor location
  782.     CMP    LAST_ROW,DH
  783.     JG    CURSOR_DN_2
  784.     CALL    SCROLL_DOWN
  785.     JMP    Short CURSOR_DN_RET
  786.  
  787. CURSOR_DN_2:
  788.     INC    DH            ;bump to next line
  789.     SCRSR                ;set cursor function
  790. CURSOR_DN_RET:
  791.     POP    CX
  792.     RET
  793.  
  794. CURSOR_DOWN    ENDP
  795.  
  796. CURSOR_LEFT    PROC    NEAR
  797. ; Handles Left Arrow key
  798.     MOV    AX,BUFFER_POSITION    ;get current buffer position
  799.     CMP    AX,Offset SCRN_BUFR    ;at beginning?
  800.     JG    CURSR_LFT_2        ;no, OK to continue
  801.     JMP    BAD_KEY
  802.  
  803. CURSR_LFT_2:
  804.     GCRSR                ;get current position
  805.     CMP    DH,FIRST_ROW        ;at top of window?
  806.     JNE    CURSR_LFT_3        ;no
  807.     CMP    DL,FIRST_COLUMN        ;at first column?
  808.     JNE    CURSR_LFT_3        ;no, move will be OK
  809.     MOV    AX,PGWIDTH        ;yes, set buffer position
  810.     SUB    BUFFER_POSITION,AX    ;to scroll up 1 line
  811.     ADD    BUFFER_LEFT,AX        ;this sets buffer positions for move
  812.     MOV    IN_LAST_PAGE,0        ;reset flag
  813.     CALL    MOVE_SCREEN        ;show the moved screen
  814.     INC    DH            ;put cursor at same character
  815.     SCRSR
  816.     CALL    BACK_CURSOR        ;now move it back
  817.     MOV    AX,PGWIDTH        ;position for end of line
  818.     MOV    LINE_POSITION,AX
  819.     DEC    AX            ;now set buffer position 1 space back
  820.     ADD    BUFFER_POSITION,AX    ;and bump pointers to line end
  821.     SUB    BUFFER_LEFT,AX
  822.     JMP    Short CURSR_LFT_RET
  823.  
  824. CURSR_LFT_3:
  825.     CMP    BUFFER_LEFT,1        ;on last position?
  826.     JNE    CURSR_LFT_4        ;no, regular case
  827.     INC    LINE_POSITION        ;special case so following code works
  828. CURSR_LFT_4:
  829.     CALL    CUR_LFT            ;make move
  830.     JC    CURSOR_LEFT_ERR        ;beep if error
  831. CURSR_LFT_RET:
  832.     POP    CX
  833.     RET
  834.  
  835. CURSOR_LEFT_ERR:
  836.     JMP    BAD_KEY
  837.  
  838. CURSOR_LEFT    ENDP
  839.  
  840. ; Moves cursor right on screen and updates buffer pointers
  841. ;
  842. CURSOR_RT    PROC NEAR
  843.     CMP    BUFFER_LEFT,1        ;past or at right end?
  844.     JNG    CUR_RHT_BAD        ;yes, set error flag
  845.     DEC    BUFFER_LEFT        ;no, decrease # of chars left
  846.     INC    BUFFER_POSITION        ;bump char position
  847.     MOV    BX,LINE_POSITION
  848.     CMP    BX,PGWIDTH        ;at end of line?
  849.     JL    CUR_RHT_0
  850.     MOV    LINE_POSITION,1        ;yes, reset position
  851. CUR_RHT_0:
  852.     INC    LINE_POSITION
  853.     CALL    ADVANCE_CURSOR
  854.     JNC    CUR_RHT_1        ;not at end of page
  855.     MOV    LINE_POSITION,1        ;point line offset at start
  856.     CALL    SCROLL_DOWN
  857. CUR_RHT_1:
  858.     POP    CX
  859.     RET
  860.  
  861. CUR_RHT_BAD:
  862.     CALL    SET_LAST_LINE
  863.     JMP    BAD_KEY
  864.  
  865. CURSOR_RT    ENDP
  866.  
  867. CURSOR_UP    PROC    NEAR
  868.     GCRSR                ;get current cursor position
  869.     CMP    DH,FIRST_ROW        ;at first row
  870.     JNE    CUR_UP_2        ;no, no need to check
  871.     MOV    IN_LAST_PAGE,0        ;yes, reset
  872.     MOV    AX,Offset SCRN_BUFR    ;check for first screen
  873.     ADD    AX,PGWIDTH        ;points to start of line 2 in buffer
  874.     CMP    BUFFER_POSITION,AX    ;is current pointer in that line?
  875.     JNL    CUR_UP_1        ;no, OK to scroll up
  876.     JMP    BAD_KEY
  877.  
  878. CUR_UP_1:
  879.     MOV    BX,PGWIDTH        ;change buffer pointers
  880.     SUB    BUFFER_POSITION,BX    ;by width of screen
  881.     ADD    BUFFER_LEFT,BX
  882.     PUSH    BUFFER_POSITION        ;save position
  883.     MOV    AX,LINE_POSITION
  884.     DEC    AX            ;adjust for base 0
  885.     SUB    BUFFER_POSITION,AX    ;point at start of line
  886.     GCRSR                ;save current cursor position
  887.     PUSH    DX
  888.     MOV    DL,FIRST_COLUMN        ;point cursor at start of line
  889.     SCRSR
  890.     CALL    MOVE_SCREEN        ;now move the screen up
  891.     POP    DX            ;restore cursor
  892.     SCRSR
  893.     POP    BUFFER_POSITION        ;restore buffer position
  894.     JMP    Short CUR_UP_RET
  895.  
  896. CUR_UP_2:
  897.     DEC    DH
  898.     SCRSR                ;set the cursor there
  899.     MOV    AX,PGWIDTH
  900.     SUB    BUFFER_POSITION,AX
  901.     ADD    BUFFER_LEFT,AX        ;bump buffer pointers
  902. CUR_UP_RET:
  903.     POP    CX
  904.     RET
  905.  
  906. CURSOR_UP    ENDP
  907.  
  908. DELETE_CHAR    PROC    NEAR
  909.     MOV    CX,BUFFER_LEFT        ;get remaining chars
  910.     DEC    CX            ;adjust count
  911.     MOV    DI,BUFFER_POSITION    ;get current address
  912.     MOV    SI,DI            ;copy
  913.     INC    SI            ;and back up one
  914.     CLD                ;make sure it's forward
  915.     REP    MOVSB
  916.     MOV    Byte Ptr 0[DI],' '    ;blank last character position
  917.     CALL    MOVE_SCREEN        ;now display the new window
  918.     POP    CX
  919.     RET
  920.  
  921. DELETE_CHAR    ENDP
  922.  
  923. DELETE_LINE    PROC    NEAR
  924.     CALL    FIND_LINE_NUMBER    ;AX returns line number
  925.     MOV    BX,PGWIDTH
  926.     MUL    BX            ;AX now has number of chars from start
  927.     PUSH    AX            ;save it
  928.     MOV    CX,FIELD_LENGTH
  929.     SUB    CX,AX
  930.     MOV    DI,Offset SCRN_BUFR    ;set up end of buffer
  931.     POP    AX
  932.     PUSH    AX            ;keep it on hold
  933.     ADD    DI,AX            ;start of move
  934.     MOV    SI,DI
  935.     ADD    SI,PGWIDTH        ;from start of next line
  936.     REP    MOVSB            ;do the move
  937.     MOV    DI,SI            ;set for blanking
  938.     MOV    CX,PGWIDTH
  939.     MOV    AL,' '            ;fill character
  940.     REP    STOSB            ;fill last line
  941.     GCRSR
  942.     MOV    DL,FIRST_COLUMN
  943.     SCRSR
  944.     POP    AX            ;get offset from start
  945.     MOV    BX,FIELD_LENGTH
  946.     SUB    BX,AX
  947.     MOV    BUFFER_LEFT,BX
  948.     ADD    AX,Offset SCRN_BUFR
  949.     MOV    BUFFER_POSITION,AX
  950.     MOV    LINE_POSITION,1
  951.     CALL    MOVE_SCREEN
  952.     POP    CX
  953.     RET
  954.  
  955. DELETE_LINE    ENDP
  956.  
  957. DELETE_TO_EOT    PROC    NEAR
  958. ; Clears from the current cursor position to the end of the text buffer.
  959.     MOV    CX,BUFFER_END        ;recalc BUFFER_LEFT
  960.     SUB    CX,BUFFER_POSITION    ;now has chars left
  961.     MOV    BUFFER_LEFT,CX
  962.     MOV    DI,BUFFER_POSITION    ;point at buffer position
  963.     MOV    AL,' '            ;clear from here
  964.     REP    STOSB
  965.     CALL    MOVE_SCREEN        ;now show the screen
  966.     POP    CX
  967.     JMP    GET_LINE_LOOP1
  968.  
  969. DELETE_TO_EOT    ENDP
  970.  
  971. DO_BREAK    PROC    NEAR
  972.     POP    DX            ;clear stack
  973.     JMP    EDIT_TXT_END_1
  974.  
  975. DO_BREAK    ENDP
  976.  
  977. DO_END    PROC    NEAR
  978.     MOV    AX,PGWIDTH        ;page width - line position
  979.     CMP    LINE_POSITION,AX    ;end of line?
  980.     JL    DO_END_1        ;no, OK to continue
  981.     JMP    BAD_KEY            ;yes, invalid key
  982.  
  983. DO_END_1:
  984.     MOV    AX,PGWIDTH
  985.     SUB    AX,LINE_POSITION    ;= # of chars to move
  986.     ADD    BUFFER_POSITION,AX    ;bump cursor position
  987.     SUB    BUFFER_LEFT,AX        ;reduce no of chars left
  988.     MOV    AX,PGWIDTH
  989.     MOV    LINE_POSITION,AX    ;set line position
  990.     MOV    AX,BUFFER_END        ;point at end of buffer
  991.     CMP    AX,BUFFER_POSITION
  992.     JNE    DO_END_2        ;not at last position
  993.     DEC    BUFFER_POSITION
  994.     MOV    BUFFER_LEFT,1
  995.     DEC    LINE_POSITION
  996. DO_END_2:
  997.     GCRSR                ;get the cursor
  998.     MOV    DL,LAST_COLUMN        ;set end position
  999.     SCRSR                ;display it
  1000.     POP    CX
  1001.     RET
  1002.  
  1003. DO_END    ENDP
  1004.  
  1005. ;    PAGE_DOWN moves to next screen. Stops with bottom of input area
  1006. ;    on last line.
  1007. ;
  1008. DO_PAGE_DOWN    PROC    NEAR
  1009.     CMP    IN_LAST_PAGE,0
  1010.     JE    PG_DN_0
  1011.     JMP    BAD_KEY
  1012.  
  1013. PG_DN_0:
  1014.     CALL    PAGE_NUMBER        ;get the current page number
  1015.     MOV    AX,SCROLL_PAGE
  1016.     MOV    BX,PAGE_SIZE
  1017.     MUL    BX            ;AX now has offset to next page line 1
  1018.     ADD    AX,Offset SCRN_BUFR    ;make it an offset to buffer
  1019.     CMP    AX,BUFFER_END        ;past end?
  1020.     JL    PG_DN_1            ;no
  1021.     SUB    AX,PAGE_SIZE        ;yes, point at start of last page
  1022.     CMP    BUFFER_POSITION,AX    ;did we move down?
  1023.     JL    PG_DN_1            ;yes
  1024.     JMP    BAD_KEY
  1025.  
  1026. PG_DN_1:
  1027.     MOV    BX,BUFFER_END        ;end of buffer
  1028.     MOV    BUFFER_POSITION,AX    ;set the buffer pointer
  1029.     ADD    AX,PAGE_SIZE
  1030.     SUB    BX,AX            ;chars left
  1031.     JNC    PG_DN_2            ;not past end
  1032.     MOV    AX,BUFFER_POSITION
  1033.     SUB    AX,PGWIDTH        ;back up one line
  1034.     MOV    IN_LAST_PAGE,0FFH    ;set flag
  1035.     JMP    PG_DN_1            ;and adjust
  1036.  
  1037. PG_DN_2:
  1038.     MOV    BX,BUFFER_END        ;calc chars left
  1039.     SUB    BX,BUFFER_POSITION
  1040.     MOV    BUFFER_LEFT,BX
  1041.     MOV    LINE_POSITION,1
  1042.     CALL    HOME_CURSOR        ;put cursor at beginning of window
  1043.     CALL    MOVE_SCREEN
  1044.     POP    CX
  1045.     RET
  1046.  
  1047. DO_PAGE_DOWN    ENDP
  1048. ;
  1049. ;    PAGE_UP moves screen to top of preceding page
  1050. ;
  1051. DO_PAGE_UP    PROC    NEAR
  1052.     MOV    AX,BUFFER_POSITION    ;current buffer position
  1053.     CMP    AX,Offset SCRN_BUFR    ;at start now?
  1054.     JG    PG_UP_1
  1055. PG_UP_0:
  1056.     JMP    BAD_KEY
  1057.  
  1058. PG_UP_1:
  1059.     CALL    PAGE_NUMBER        ;get page of current buffer pointers
  1060.     CMP    IN_LAST_PAGE,0        ;in last page?
  1061.     JE    PG_UP_2            ;no
  1062.     MOV    IN_LAST_PAGE,0        ;yes, reset
  1063. PG_UP_2:
  1064.     MOV    AX,SCROLL_PAGE        ;put it in AX
  1065.     CMP    AX,1            ;in first page?
  1066.     JE    PG_UP_0
  1067.     SUB    AX,2            ;page to be in adjsted to base 0
  1068.     MUL    PAGE_SIZE        ;AX now has offset from start of buffer
  1069.     ADD    AX,Offset SCRN_BUFR    ;make it actual position
  1070.     MOV    BUFFER_POSITION,AX    ;set buffer position
  1071.     SUB    AX,Offset SCRN_BUFR    ;calculate buffer left
  1072.     MOV    BX,FIELD_LENGTH
  1073.     SUB    BX,AX
  1074.     MOV    BUFFER_LEFT,BX
  1075.     MOV    LINE_POSITION,1
  1076.     CALL    HOME_CURSOR        ;put cursor at beginning of window
  1077.     CALL    MOVE_SCREEN
  1078.     POP    CX
  1079.     RET
  1080.  
  1081. DO_PAGE_UP    ENDP
  1082.  
  1083. DO_RETURN    PROC    NEAR
  1084.     MOV    AX,BUFFER_POSITION    ;calculate buffer change
  1085.     SUB    AX,Offset SCRN_BUFR    ;from current position
  1086.     XOR    DX,DX
  1087.     DIV    PGWIDTH            ;mod value in AX
  1088.     INC    AX            ;round up to start of next line
  1089.     MUL    PGWIDTH
  1090.     ADD    AX,Offset SCRN_BUFR
  1091.     SUB    AX,BUFFER_POSITION    ;AX has # of chars left
  1092.     ADD    BUFFER_POSITION,AX    ;current position
  1093.     MOV    LINE_POSITION,1        ;set line char count
  1094.     SUB    BUFFER_LEFT,AX        ;# of remaining chars
  1095.     JG    DO_RETURN_1        ;at end of input area?
  1096.     MOV    AX,BUFFER_END
  1097.     SUB    AX,PGWIDTH
  1098.     MOV    BUFFER_POSITION,AX
  1099.     MOV    LINE_POSITION,1
  1100.     MOV    IN_LAST_PAGE,0FFH
  1101.     MOV    AX,PGWIDTH
  1102.     MOV    BUFFER_LEFT,AX
  1103.     JMP    BAD_KEY            ;go write file
  1104.  
  1105. DO_RETURN_1:
  1106.     GCRSR                ;get cursor location
  1107.     CMP    LAST_ROW,DH
  1108.     JG    DO_RETURN_2
  1109.     CALL    SCROLL_DOWN
  1110.     POP    CX
  1111.     RET
  1112.  
  1113. DO_RETURN_2:
  1114.     INC    DH            ;bump to next line
  1115.     MOV    DL,FIRST_COLUMN        ;start of next line
  1116.     SCRSR                ;set cursor function
  1117.     POP    CX
  1118.     RET
  1119.  
  1120. DO_RETURN    ENDP
  1121.  
  1122. DO_TAB    PROC    NEAR
  1123.     MOV    BX,BUFFER_LEFT        ;save in register
  1124.     MOV    REG4,BX
  1125.     GCRSR                ;get cursor location function
  1126.     MOV    AL,DL            ;copy horizontal location
  1127.     MOV    CH,AL
  1128.     ADD    AL,08H            ;add tab increment
  1129.     AND    AL,0F8H            ;round down to multiple of 8
  1130.     CMP    AL,LAST_COLUMN        ;end of line?
  1131.     JL    DO_TAB_0
  1132.     JMP    DO_RETURN        ;yes, same as CR
  1133.  
  1134. DO_TAB_0:
  1135.     XOR    AH,AH
  1136.     MOV    HCURSOR_SAVE,AL        ;save the position
  1137.     SUB    AL,CH            ;get difference
  1138.     MOV    Word Ptr BUFFER_LEFT,AX    ;put difference in BUFFER_LEFT
  1139.     MOV    BX,BUFFER_LEFT
  1140.     MOV    REG5,BX
  1141.     MOV    BX,REG4
  1142.     MOV    BUFFER_LEFT,BX
  1143.     CMP    BX,REG5
  1144.     JNL    DO_TAB_1
  1145.     JMP    DO_RETURN
  1146.  
  1147. DO_TAB_1:
  1148.     MOV    BX,REG5            ;get difference
  1149.     ADD    BUFFER_POSITION,BX    ;bump buffer position
  1150.     ADD    LINE_POSITION,BX    ;and line char position
  1151.     SUB    BUFFER_LEFT,BX        ;decremant remaining chars
  1152.     GCRSR                ;get cursor function
  1153.     MOV    DL,HCURSOR_SAVE        ;get horizontal position
  1154.     SCRSR                ;set cursor function
  1155.     POP    CX
  1156.     RET
  1157.  
  1158. DO_TAB    ENDP
  1159.  
  1160. END_SCREEN    PROC    NEAR
  1161.     MOV    AX,Offset SCRN_BUFR
  1162.     ADD    AX,FIELD_LENGTH
  1163.     SUB    AX,PAGE_SIZE
  1164.     MOV    BUFFER_POSITION,AX
  1165.     MOV    AX,PAGE_SIZE
  1166.     MOV    BUFFER_LEFT,AX
  1167.     MOV    LINE_POSITION,1
  1168.     MOV    IN_LAST_PAGE,0FFH
  1169.     CALL    HOME_CURSOR
  1170.     CALL    MOVE_SCREEN
  1171.     POP    CX
  1172.     RET
  1173.  
  1174. END_SCREEN    ENDP
  1175.  
  1176. HELP    PROC    NEAR
  1177. ; Displays pre-defined Help screen.  This routine does not test for max
  1178. ; line and page sizes because it is purely internal to this editor and
  1179. ; its input is under control of only the programmer.
  1180.     MOV    AH,0FH            ;get video mode
  1181.     INT    010H
  1182.     CMP    AL,07H            ;is it mono?
  1183.     JNE    HELP_1            ;no, OK to continue
  1184.     JMP    BAD_KEY            ;yes, beep and return
  1185.  
  1186. HELP_1:
  1187.     GCRSR                ;save cursor position on screen 0
  1188.     PUSH    DX
  1189.     CMP    HELP_SW,0        ;need to build screen?
  1190.     JNE    HELP_3            ;no, already done
  1191.     MOV    HELP_SW,0FFH        ;set HELP entered flag
  1192.     MOV    AL,02H            ;page 2 (because of line 26 indicators)
  1193.     MOV    AH,05H
  1194.     INT    010H            ;set page
  1195.     MOV    CH,0            ;set window @ full page
  1196.     MOV    CL,0
  1197.     MOV    DL,79
  1198.     MOV    DH,24
  1199.     MOV    BH,ATTRIBUTE
  1200.     MOV    AL,0
  1201.     MOV    AH,06H            ;initialize and clear window
  1202.     INT    010H
  1203.     MOV    BH,2            ;page
  1204.     MOV    DH,0            ;row for cursor screen
  1205.     MOV    DL,0              ;column
  1206.     MOV    AH,02H            ;set cursor position
  1207.     INT    010H
  1208.     MOV    CX,25*80        ;set # to scan at max
  1209.     MOV    SI,Offset HELP_TEXT
  1210. HELP_2:
  1211.     PUSH    CX            ;save count
  1212.     LODSB                ;get the character
  1213.     CMP    AL,EOL            ;end of message char?
  1214.     JNE    HELP_4            ;no, keep looping
  1215.     POP    CX            ;yes, clear PUSH
  1216.     JMP    Short HELP_3        ;and exit
  1217.  
  1218. HELP_4:
  1219.     CMP    AL,CR            ;is it <CR>?
  1220.     JNE    HELP_2A            ;no
  1221.     INC    DH            ;yes, bump line
  1222.     MOV    DL,1            ;and put cursor at start of row
  1223.     MOV    BH,02H            ;page
  1224.     MOV    AH,02H
  1225.     INT    010H
  1226.     JMP    Short HELP_2X            ;continue loop
  1227.  
  1228. HELP_2A:
  1229.     CMP    AL,LF
  1230.     JE    HELP_2X
  1231.     MOV    CX,1            ;output the character
  1232.     MOV    AH,0AH
  1233.     INT    010H
  1234.     MOV    BH,02H            ;page
  1235.     CMP    DL,78            ;at end of line?
  1236.     JLE    $$0001            ;no
  1237.     MOV    DL,0            ;yes, set column
  1238.     INC    DH            ;and bump row
  1239. $$0001:
  1240.     INC    DL            ;bump column
  1241.     MOV    AH,02            ;set the cursor
  1242.     INT    010H
  1243. HELP_2X:
  1244.     POP    CX            ;restore the count
  1245.     LOOP    HELP_2            ;keep looking
  1246. HELP_3:                ;executed when help screen is complete
  1247.     MOV    AL,2            ;switch screen to page 2
  1248.     MOV    AH,05H
  1249.     INT    010H
  1250.     MOV    AH,08H            ;any key clears help
  1251.     INT    021H            ;wait for input
  1252.     CMP    AL,0            ;extended char?
  1253.     JNE    HELP_3A            ;no
  1254.     INT    021H            ;yes, read another to clear
  1255. HELP_3A:
  1256.     MOV    AL,0            ;switch back to page 0
  1257.     MOV    AH,05H
  1258.     INT    010H
  1259.     POP    DX            ;get input cursor position
  1260.     SCRSR                ;restore it
  1261.     POP    CX
  1262.     RET
  1263.  
  1264. HELP    ENDP
  1265.  
  1266. HOME_KEY    PROC    NEAR
  1267. ; Moves cursor to beginning of current line
  1268.     GCRSR                ;get cursor
  1269.     MOV    DL,FIRST_COLUMN        ;point at start
  1270.     SCRSR
  1271.     MOV    AX,BUFFER_POSITION    ;current position
  1272.     SUB    AX,Offset SCRN_BUFR
  1273.     XOR    DX,DX
  1274.     MOV    BX,PGWIDTH
  1275.     DIV    BX
  1276.     MUL    BX            ;set to start of line
  1277.     ADD    AX,Offset SCRN_BUFR
  1278.     MOV    BUFFER_POSITION,AX    ;number of chars
  1279.     MOV    LINE_POSITION,1        ;set back at start
  1280.     MOV    AX,BUFFER_END
  1281.     SUB    AX,BUFFER_POSITION
  1282.     MOV    BUFFER_LEFT,AX        ;recalc remaining chars
  1283.     POP    CX
  1284.     RET
  1285.  
  1286. HOME_KEY    ENDP
  1287.  
  1288. INSERT    PROC    NEAR
  1289.     XOR    INSERT_TOGGLE,0FFH    ;flip toggle
  1290.     CALL    SHOW_INSERT
  1291.     POP    CX
  1292.     RET
  1293.  
  1294. INSERT    ENDP
  1295.  
  1296. INSERT_LINE    PROC    NEAR
  1297. ;
  1298.     CALL    FIND_LINE_NUMBER    ;AX returns line number
  1299.     MOV    BX,PGWIDTH
  1300.     MUL    BX            ;AX now has number of chars from start
  1301.     PUSH    AX
  1302.     MOV    CX,FIELD_LENGTH
  1303.     SUB    CX,AX
  1304.     SUB    CX,BX            ;CX has chars to move
  1305.     MOV    DI,Offset SCRN_BUFR    ;set up end of buffer
  1306.     ADD    DI,FIELD_LENGTH
  1307.     DEC    DI            ;points at last character
  1308.     MOV    SI,DI
  1309.     SUB    SI,PGWIDTH        ;start of move
  1310.     STD                ;move from end of buffer
  1311.     REP    MOVSB            ;do the move
  1312.     MOV    CX,PGWIDTH
  1313.     MOV    AL,' '            ;fill character
  1314.     REP    STOSB            ;fill last line
  1315.     CLD                ;reset
  1316.     GCRSR
  1317.     MOV    DL,FIRST_COLUMN
  1318.     SCRSR
  1319.     POP    AX            ;get offset from start
  1320.     MOV    BX,FIELD_LENGTH
  1321.     SUB    BX,AX
  1322.     MOV    BUFFER_LEFT,BX
  1323.     ADD    AX,Offset SCRN_BUFR
  1324.     MOV    BUFFER_POSITION,AX
  1325.     MOV    LINE_POSITION,1
  1326.     CALL    MOVE_SCREEN
  1327.     POP    CX
  1328.     RET
  1329.  
  1330. INSERT_LINE    ENDP
  1331.  
  1332. START_SCREEN    PROC    NEAR
  1333.     MOV    AX,FIELD_LENGTH
  1334.     MOV    BUFFER_LEFT,AX
  1335.     MOV    BUFFER_POSITION,Offset SCRN_BUFR
  1336.     MOV    LINE_POSITION,1
  1337.     MOV    IN_LAST_PAGE,0
  1338.     CALL    HOME_CURSOR        ;put cursor at beginning of window
  1339.     CALL    MOVE_SCREEN
  1340.     POP    CX
  1341.     RET
  1342.  
  1343. START_SCREEN    ENDP
  1344.  
  1345.     SUBTTL    Subroutines (CALLed Routines)
  1346.     PAGE
  1347.  
  1348. ADVANCE_CURSOR    PROC    NEAR
  1349. ; Advances the cursor position on the screen.
  1350. ; Does not update memory pointers.
  1351. ; Returns carry if SKIP_FLAG = 0 and line advances
  1352.     PUSH    AX
  1353.     GCRSR                ;get cursor location function
  1354.     CMP    DL,LAST_COLUMN        ;end of line?
  1355.     JE    ADV_CRSR_1
  1356.     INC    DL            ;bump column position on screen
  1357.     JMP    Short ADV_CRSR_2
  1358.  
  1359. ADV_CRSR_1:
  1360.     CMP    DH,LAST_ROW        ;on last row?
  1361.     JE    ADV_CRSR_3        ;yes, scroll screen
  1362.     MOV    DL,FIRST_COLUMN
  1363.     INC    DH
  1364. ADV_CRSR_2:
  1365.     SCRSR                ;set cursor location function
  1366.     CLC                ;clear carry flag
  1367.     JMP    Short ADV_CRSR_RET
  1368.  
  1369. ADV_CRSR_3:
  1370.     CMP    SKIP_FLAG,0        ;no scroll flag set?
  1371.     JNE    ADV_CRSR_RET        ;yes
  1372.     STC                ;set CY
  1373. ADV_CRSR_RET:
  1374.     POP    AX
  1375.     RET
  1376.  
  1377. ADVANCE_CURSOR    ENDP
  1378.  
  1379. BACK_CURSOR    PROC    NEAR
  1380. ; Backs the cursor up one position.  Depends on caller knowing that the
  1381. ; move is OK
  1382. ; Does not update memory pointers.
  1383.     PUSH    AX
  1384.     GCRSR                ;get the current position
  1385.     CMP    DL,FIRST_COLUMN        ;is it at start?
  1386.     JLE    BCK_CUR_1        ;yes, move to previous line
  1387.     DEC    DL            ;no, just reduce it
  1388.     JMP    Short BCK_CUR_2
  1389.  
  1390. BCK_CUR_1:
  1391.     MOV    DL,LAST_COLUMN        ;end of line
  1392.     DEC    DH            ;up one line
  1393. BCK_CUR_2:
  1394.     SCRSR                ;now reset it
  1395.     POP    AX
  1396.     RET
  1397.  
  1398. BACK_CURSOR    ENDP
  1399.  
  1400. BEEP    PROC    NEAR        ;sounds alarm
  1401.     MOV    DL,BEL
  1402.     MOV    AH,06H
  1403.     INT    021H
  1404.     RET
  1405.  
  1406. BEEP    ENDP
  1407.  
  1408. CUR_LFT        PROC    NEAR
  1409. ; Move the cursor left on the screen and adjust memory pointers
  1410.     MOV    BX,Offset SCRN_BUFR    ;check for start of data
  1411.     CMP    BX,BUFFER_POSITION    ;at beginning?
  1412.     JNL    CUR_LFT_BAD        ;yes, set error indication
  1413.     DEC    BUFFER_POSITION        ;no, set position back one
  1414.     INC    BUFFER_LEFT        ;bump remaining characters
  1415.     CMP    LINE_POSITION,1        ;at line start?
  1416.     JNE    CUR_LFT_1
  1417.     MOV    BX,PGWIDTH
  1418.     MOV    LINE_POSITION,BX    ;yes, set new line at end
  1419.     JMP    Short CUR_LFT_2
  1420.  
  1421. CUR_LFT_1:
  1422.     DEC    LINE_POSITION        ;keep line char count
  1423. CUR_LFT_2:
  1424.     CALL    BACK_CURSOR        ;set cursor position on screen
  1425.     CLC                ;clear error
  1426.     RET
  1427.  
  1428. CUR_LFT_BAD:
  1429.     STC                ;set carry
  1430.     RET
  1431.  
  1432. CUR_LFT    ENDP
  1433.  
  1434. FIND_LINE_NUMBER    PROC    NEAR
  1435. ; Returns current line number in AX (starts at 0)
  1436.     PUSH    DX
  1437.     PUSH    BX
  1438.     MOV    AX,BUFFER_POSITION
  1439.     SUB    AX,Offset SCRN_BUFR
  1440.     MOV    BX,PGWIDTH
  1441.     XOR    DX,DX
  1442.     DIV    BX
  1443.     POP    BX
  1444.     POP    DX
  1445.     CLC
  1446.     RET
  1447.  
  1448. FIND_LINE_NUMBER    ENDP
  1449.  
  1450. HOME_CURSOR    PROC    NEAR
  1451.     GCRSR
  1452.     MOV    DL,FIRST_COLUMN
  1453.     MOV    DH,FIRST_ROW
  1454.     SCRSR
  1455.     RET
  1456.  
  1457. HOME_CURSOR    ENDP
  1458.  
  1459. MOVE_SCREEN    PROC    NEAR
  1460. ; Moves data from buffer pointed to by BUFFER_POSITION to current cursor position
  1461. ; for length of screen
  1462.     GCRSR                ;get cursor function
  1463.     PUSH    DX
  1464.     MOV    BX,PGWIDTH
  1465.     XOR    AX,AX            ;clear
  1466.     MOV    AL,LAST_ROW        ;calculate total screen space
  1467.     SUB    AL,FIRST_ROW
  1468.     INC    AX
  1469.     MUL    BX            ;AX now has total
  1470.     POP    DX            ;restore DX
  1471.     PUSH    AX            ;save total
  1472.     PUSH    DX            ;hold it again
  1473.     XOR    AX,AX
  1474.     MOV    AL,DH            ;get current row
  1475.     SUB    AL,FIRST_ROW        ;calculate space used
  1476.     MUL    BX
  1477.     POP    DX            ;restore original position
  1478.     ADD    AL,DL            ;add current offset
  1479.     ADC    AH,0            ;take care of carry
  1480.     SUB    AX,FIRST_COL_WORD    ;get rid of unused columns
  1481.     NEG    AX
  1482.     POP    CX            ;get total space (PUSHed from AX)
  1483.     ADD    CX,AX            ;calculate size to move
  1484.     PUSH    SKIP_FLAG        ;save current setting
  1485.     MOV    SKIP_FLAG,1        ;no scroll at end of screen
  1486.     PUSH    DX            ;save cursor position
  1487.     MOV    SI,BUFFER_POSITION    ;initialize pointer for display char
  1488. MOVE_SCRN_LOOP:
  1489.     LODSB                ;put character in AL
  1490.     WCRSR
  1491.     CALL    ADVANCE_CURSOR
  1492.     LOOP    MOVE_SCRN_LOOP
  1493.     POP    DX
  1494.     POP    SKIP_FLAG        ;restore
  1495.     SCRSR                ;reposition
  1496.     RET
  1497.  
  1498. MOVE_SCREEN    ENDP
  1499.  
  1500. PAGE_NUMBER    PROC    NEAR
  1501. ; Finds the page number associated with the current buffer position pointers
  1502. ; Returns it in word field SCROLL_PAGE
  1503.     PUSH    AX            ;save registers used
  1504.     PUSH    BX
  1505.     PUSH    CX
  1506.     PUSH    DX
  1507.     MOV    SCROLL_PAGE,0        ;initialize
  1508.     MOV    AX,FIELD_LENGTH        ;calculate number to loop
  1509.     XOR    DX,DX
  1510.     DIV    PAGE_SIZE
  1511.     MOV    CX,AX            ;CX has max number of pages
  1512.     INC    CX
  1513.     MOV    BX,CX            ;save max pages
  1514.     MOV    AX,Offset SCRN_BUFR
  1515.     CMP    IN_LAST_PAGE,0        ;now in last page?
  1516.     JE    PG_NUM_1        ;no
  1517.     MOV    SCROLL_PAGE,CX
  1518.     STC                ;let us know how we got last page
  1519.     JMP    Short PG_NUM_RET
  1520.  
  1521. PG_NUM_1:
  1522.     INC    SCROLL_PAGE        ;bump page number
  1523.     ADD    AX,PAGE_SIZE        ;bump next page start
  1524.     CMP    AX,BUFFER_POSITION    ;is it in here?
  1525.     JG    PG_NUM_2
  1526.     LOOP    PG_NUM_1
  1527.     DEC    SCROLL_PAGE        ;went past end, set back
  1528.     STC                ;shouldn't drop through
  1529.     JMP    Short PG_NUM_RET
  1530.  
  1531. PG_NUM_2:
  1532.     CLC                ;page OK
  1533. PG_NUM_RET:
  1534.     POP    DX            ;restore registers used
  1535.     POP    CX
  1536.     POP    BX
  1537.     POP    AX
  1538.     RET
  1539.  
  1540. PAGE_NUMBER    ENDP
  1541.  
  1542. SCROLL_DOWN    PROC    NEAR
  1543. ; Scrolls the screen down one line
  1544.     PUSH    SI
  1545.     PUSH    DX
  1546.     PUSH    CX
  1547.     PUSH    BX
  1548.     PUSH    AX
  1549.     XOR    BX,BX            ;clear
  1550.     MOV    BH,ATTRIBUTE        ;attribute to fill with
  1551.     MOV    AH,06H            ;scroll window up function
  1552.     MOV    AL,01H            ;scroll 1 line
  1553.     MOV    CH,FIRST_ROW
  1554.     MOV    CL,FIRST_COLUMN
  1555.     MOV    DH,LAST_ROW
  1556.     MOV    DL,LAST_COLUMN
  1557.     INT    010H
  1558.     MOV    BX,LINE_POSITION    ;calculate cursor offset
  1559.     ADD    BL,FIRST_COLUMN        ;from current line offset
  1560.     DEC    BX            ;screen position is base 0
  1561.     MOV    DL,BL
  1562.     MOV    DH,LAST_ROW
  1563.     SCRSR
  1564.     MOV    SI,BUFFER_POSITION    ;offset of data
  1565.     SUB    SI,LINE_POSITION
  1566.     INC    SI            ;account for base 0
  1567.     MOV    CX,PGWIDTH        ;amount to move
  1568.     XOR    BX,BX            ;clear
  1569.     GCRSR
  1570.     MOV    REG8,DX            ;save current position
  1571.     MOV    DL,FIRST_COLUMN        ;point at start of line
  1572.     SCRSR                ;put cursor there
  1573. SCRL_DN_1:
  1574.     PUSH    CX
  1575.     MOV    CX,1
  1576.     LODSB
  1577.     WCRSR                 ;display char function
  1578.     INC    DL
  1579.     SCRSR
  1580.     POP    CX
  1581.     LOOP    SCRL_DN_1
  1582.     MOV    DX,REG8            ;get cursor position
  1583.     SCRSR                ;restore it
  1584.     POP    AX
  1585.     POP    BX
  1586.     POP    CX
  1587.     POP    DX
  1588.     POP    SI
  1589.     RET
  1590.  
  1591. SCROLL_DOWN    ENDP
  1592.  
  1593. SET_LAST_LINE    PROC    NEAR
  1594. ; Allows entry on last line after an error
  1595.     MOV    AX,FIELD_LENGTH        ;get no of characters
  1596.     ADD    AX,Offset SCRN_BUFR    ;end of characters
  1597.     DEC    AX
  1598.     MOV    BUFFER_POSITION,AX    ;set buffer position
  1599.     MOV    AX,PGWIDTH        ;set line position
  1600.     DEC    AX            ;at end
  1601.     MOV    LINE_POSITION,AX
  1602.     MOV    BUFFER_LEFT,1        ;set number of chars
  1603.     GCRSR                ;get cursor position
  1604.     MOV    DL,LAST_COLUMN        ;position column
  1605.     MOV    DH,LAST_ROW
  1606.     SCRSR                ;move cursor to end of window
  1607.     RET
  1608.  
  1609. SET_LAST_LINE    ENDP
  1610.  
  1611. DO_ESCAPE:
  1612.     JMP    BAD_KEY
  1613.  
  1614.  
  1615. CNVT_DEC    PROC    NEAR
  1616. ;    Converts an ASCIIZ numeric string in the field ARGUMENT
  1617. ;    to a hex value in AX
  1618.     MOV    BP,0            ;set index
  1619.     XOR    AX,AX            ;clear result
  1620.     MOV    BX,10            ;base
  1621.     XOR    CX,CX
  1622. CNVT_DEC_LOOP:
  1623.     MOV    AL,Byte Ptr ARGUMENT[BP]
  1624.     CMP    AL,0            ;end of number?
  1625.     JE    CNVT_DEC_RET        ;yes
  1626.     CMP    AL,' '            ;no, is it blank?
  1627.     JE    CNVT_DEC_LOOP2        ;yes, keep searching for data
  1628.     SUB    AL,'0'            ;no, convert to binary
  1629.     PUSH    AX            ;save digit
  1630.     MOV    AX,CX            ;get current sum
  1631.     MUL    BX            ;multiply by 10
  1632.     MOV    CX,AX            ;put result in total
  1633.     POP    AX            ;get new digit
  1634.     ADD    CX,AX            ;add in to low order
  1635.     XOR    AX,AX            ;clear
  1636. CNVT_DEC_LOOP2:
  1637.     INC    BP            ;bump to next digit
  1638.     JMP    CNVT_DEC_LOOP        ;go process
  1639.  
  1640. CNVT_DEC_RET:
  1641.     RET                ;back to caller
  1642.  
  1643. CNVT_DEC    ENDP
  1644.  
  1645. SHOW_INSERT    PROC    NEAR
  1646. ; Shows the current status of the INS key
  1647.     PUSH    ES
  1648.     MOV    AX,0B800H        ;in general case could be 0B000H
  1649.     MOV    ES,AX
  1650.     CMP    INSERT_TOGGLE,0        ;insert off?
  1651.     JNE    SHO_INS_2        ;no, must be on
  1652.     MOV    SI,Offset THREE_BLANKS
  1653.     JMP    Short SHO_INS_3
  1654.  
  1655. SHO_INS_2:
  1656.     MOV    SI,Offset INS_STRING
  1657. SHO_INS_3:
  1658.     MOV    DI,80            ;offset of INS char in buffer
  1659.     MOV    CX,3
  1660. SHO_INS_4:
  1661.     MOVSB
  1662.     INC    DI            ;bump past attribute
  1663.     LOOP    SHO_INS_4
  1664.     POP    ES            ;restore
  1665.     RET
  1666.  
  1667. SHOW_INSERT    ENDP
  1668.  
  1669. SCRN_BUFR    DB    MAXLEN DUP(' ')
  1670. SCRN_BUFR_END:
  1671.         DB    100 dup (?)    ;extra space for safety's sake
  1672.  
  1673. DBASEDIT    ENDP
  1674.  
  1675. CSEG    ENDS
  1676.     END
  1677.